﻿CREATE PROCEDURE [dbo].[proc_Assets_Getlist_TongJiXX]
	(
		@CompanyId int,
		@CategoryId int,
		@NameId int,
		@StateId int,
		@StartIndex int,
		@EndIndex INT

	)
AS
	;WITH list as (Select ROW_NUMBER() OVER (ORDER BY a.Id)AS Row,
	a.Id,
	a.GId,
	a.CategoryId,
	(Select Title From Assets_Categorys Where Id=a.CategoryId) As CategoryName,
	NameId,
	(Select Title From Assets_Names Where Id=a.NameId) As NameTitle,
	Description,
	CompanyId,
	(Select CompanyName From Company Where Id=a.CompanyId) As CompanyName,	
	UserName,
	--EName,
	StateId,
	(Select Title From Assets_States Where Id=a.StateId) As StateName,
	Prices,
	DJUserName,
	DJDate,
	GGXH,
	GZDate,
	IsNULL(IsApplyBf,0) AS IsApplyBf,
	ANumber,
	IsNull(LyDate,'1900-01-01') as LyDate,
	ename+'('+(Select DName From Department Where Id=a.DepartmentId)+')' as EName 
	From Assets a
	Where ( a.CompanyId=@CompanyId)  and
	 ( a.NameId=@NameId) and ( a.StateId=@StateId)
	 
	)
	
	Select * From list,(Select Count(Id) AS cid From list
	) AS n Where Row between @StartIndex and @EndIndex
	
	RETURN
